package gspushmq.v1.main;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import ggframework.util.GGConfigurer;
import gspushmq.model.GGQueueConstant;
import gspushmq.util.GGLogger;
import gspushmq.v1.produce.job.core.GGRabbitMQ;
import gspushmq.v1.produce.job.sys.GGMQRealTimeJob;

/**
 *
 * @description 启动mq
 * @param
 * @version 1.0
 * @author chengsja
 * @date 2018/12/20 16:14
 *
 */
public class GGRabbitMQEnable {
	
	public static void start() {
		if (!GGConfigurer.containsKey("ggmes.host")) {
			return;
		}
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost(GGConfigurer.get("ggmes.host"));
		factory.setPort(GGConfigurer.getInteger("ggmes.port"));
		factory.setVirtualHost(GGConfigurer.get("ggmes.vhost"));
		factory.setUsername(GGConfigurer.get("ggmes.username"));
		factory.setPassword(GGConfigurer.get("ggmes.password"));
		try {
			Connection connection = factory.newConnection();
			GGRabbitMQ.GG_RABBIT_MQ.setConnection(connection);
			GGMQRealTimeJob.consume(GGConfigurer.get("PUSH_WARING", GGQueueConstant.PUSH_WARING));
		} catch (Exception e) {
			GGLogger.error(GGRabbitMQEnable.class, e, "创建GGMessage连接异常");
		}
	}
	public static void destory() {
		GGRabbitMQ.GG_RABBIT_MQ.destory();
	}

}